﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Data.SqlClient;
using cart.utils;
using cart.model;


namespace cart.dao
{
    public class postDao
    {
        public ArrayList getProvince()
        {
            string SELECT_POST_PROVINCE = "select * from post where postTypeMasterId=0";
            return getPost(SELECT_POST_PROVINCE);

        }
        public ArrayList getCityByProvince(string province)
        {
            string SELECT_POST_BY_PROVINCE = "select * from post where postTypeMasterId="+province;
            return getPost(SELECT_POST_BY_PROVINCE);
        }
        private ArrayList getPost(string sql) 
        {
            ArrayList al = new ArrayList();
            SqlConnection conn = DB.getSqlConnection();
            DB.connectionOpen(conn);
            SqlCommand cmd = new SqlCommand(sql, conn);

            //if (null != parms)
            //{
            //    foreach (SqlParameter parm in parms)
            //    {
            //        cmd.Parameters.Add(parms);
            //    }
            //}

            SqlDataReader sdr = cmd.ExecuteReader();

            while (sdr.Read())
            {
                postModel pm = new postModel();
                pm.postTypeId = sdr.GetString(0);
                pm.postTypeMasterId = sdr.GetString(1);
                pm.postName = sdr.GetString(2);
                al.Add(pm);
            }

            DB.connectionClose(conn);
            return al;
        }
    }
}
